﻿@model Apps.Models.Flow.Flow_FormContentModel
@using Apps.Common;
@using Apps.Models.Flow;
@using Apps.Web.Core;
@using Apps.Models.Sys;
@using Apps.Models.Enum;
@using Apps.Locale;
@{
    ViewBag.Title = "审批";
    Layout = "~/Views/Shared/_Index_LayoutEdit2.cshtml";
    List<permModel> perm = null;
    string html =ViewBag.Html.ToString(); 
}

<div id="modalwindow" class="easyui-window" data-options="modal:true,closed:true,minimizable:false,shadow:false"></div>
@Html.HiddenFor(model => model.Id)
@Html.HiddenFor(model => model.FormId)
@Html.HiddenFor(model => model.UserId)
<input id="CustomMember" name="CustomMember" type="hidden" value="">
<input id="CreateTime" type="hidden" name="CreateTime" value="2000-1-1" />
<div class="easyui-panel" style="width:99%;padding:0px;"> 
    <table class="mvctool bgb " style="width:100%;padding:0px">
        <tbody>
            <tr>
                <td>
                    <div class="mvctool bgb" style="width:100%;">
                        @if(ViewBag.StepCheckId != "")
                    {
                if (ViewBag.IsStartStep)
                {
                                @Html.FlowToolButton("btnSave", "fa fa-save", Resource.Save, ref perm, "Create", true)
                                @Html.Raw("&nbsp;")
                                @Html.FlowToolButton("btnSubmit", "fa fa-sign-in", Resource.Submit, ref perm, "Create", true)
                                @Html.Raw("&nbsp;")
                                @Html.FlowToolButton("btnStop", "fa fa-ban", "终止", ref perm, "Edit", true)
                }
                else
                {
                                @Html.FlowToolButton("btnCheck", "fa fa-sign-in", Resource.Approve, ref perm, "Check", true)
                                @Html.Raw("&nbsp;")
                                @Html.FlowToolButton("btnUnCheck", "fa fa-rotate-left", Resource.UnCheck, ref perm, "UnCheck", true)
                }
                    }
                    @if (!string.IsNullOrEmpty(Model.UserName))
                    {
                        @Html.FlowToolButton("btnQueryFlow", "fa fa-reorder", "流程情况", ref perm, "Query", true)
                    }
                        @Html.ToolButton("btnFlowReturn", "fa fa-reply", Resource.Reply, false)
                    </div>
                </td>
                @if (!string.IsNullOrEmpty(Model.UserName))
                {
                <th>申请人：</th>
                <td>@( Model.DepName + "-" + Model.PosName + "|" + Model.TrueName)</td>
                }
                @*<th>@Html.LabelFor(model => model.TimeOut)：</th>
                    <td>@(Convert.ToDateTime(Model.TimeOut).ToShortDateString())</td>*@
                <th style='width:80px;'>紧急程度 :</th>
                <td>@((int.Parse(Model.FormLevel) == (int)FlowFormLevelEnum.Ordinary) ? "普通" : ((int.Parse(Model.FormLevel) == (int)FlowFormLevelEnum.Major) ? "重要" : "紧急"))</td>
                <th style='width:20px;'></th>
            </tr> 
        </tbody>
    </table> 
</div>

<div id="setFormLayout" class="easyui-panel"  style="width:99%;padding-left:0px;padding-right:0px;padding-top:4px;padding-bottom:4px">
    <iframe id="ywForm" src="../../@(html +"/"+ Model.Id)" frameborder="0" style="width:100%; height:100%; overflow-x:hidden;"></iframe>
</div>
<script>
    $(function () {
        $("#setFormLayout").css("width", SetGridWidthSub(40));
        $("#setFormLayout").css("height", SetGridHeightSub(50));

        $("#ywForm").css("height", SetGridWidthSub(30));
        $("#ywForm").css("height", SetGridHeightSub(50));

        $("#btnCheck").click(function () {
            NextStep(@((int)FlowStateEnum.Pass));
        });

        $("#btnUnCheck").click(function () {
            NextStep(@((int)FlowStateEnum.Reject));
        });

        $("#btnStop").click(function () {
            $.post("@Url.Action("EditExternal")", { "Remark": "", "TheSeal": "", "FormId": '@(Model.FormId)', "Flag": 3, "ContentId": $("#Id").val(), "UserList": "", "NextStepId": "" },
            function (data) {
                if (data.type == 1) {
                    //结束流程
                    ywForm.window.updateState('@Model.Id', '@Model.FormId', 4);
                    window.parent.frameReturnByMes(data.message);
                    window.parent.frameReturnByReload(true);
                    window.parent.frameReturnByClose();
                }
                else {
                    $.messageBox5s(Lang.Tip, data.message);
                }
            }, "json");
        });

        $("#btnQueryFlow").click(function () {
            $("#modalwindow").html("<iframe width='100%' height='100%' scrolling='auto' frameborder='0' src='@Url.Action("Details")?id=" + '@(Model.FormId)' + "&contentId=" + $("#Id").val() + "&Ieguid=" + GetGuid() + "'></iframe>");
            $("#modalwindow").window({ title: '流程情况', width: 800, height: 420, iconCls: 'fa fa-list' }).window('open');
        });

        $("#btnFlowReturn").click(function () {
            window.parent.frameReturnByClose();
        });

        //function load(url, data){
        //    $.ajaxSetup({ cache: false });
        //    $("#setFormLayout").load($(url).attr("href"), data, function (result) {
        //        //将被加载页的JavaScript加载到本页执行
        //        $result = $(result);
        //        $result.find("script").appendTo('#setFormLayout');
        //    });
        //}

        //$("#setFormLayout").click();


    });

    //回到起草提交调用
    function PostForm(value) {
        NextStep(@((int)FlowStateEnum.Pass));
    }


    function frameReturnByClose() {
        $("#modalwindow").window('close');
    }

    function NextStep(flag) {
        var curStepId = "@ViewBag.StepCheckId";
        if (curStepId == null || curStepId == "") {
            $.messageBox5s(Lang.Tip, "不能审批");
            return false;
        }

        var title = flag == 0 ? "选择退回步骤" : "选择下一步骤";
        $("#modalwindow").html("<iframe width='100%' height='100%' scrolling='auto' frameborder='0' src='@Url.Action("StepLookUp")?contentId=" + $("#Id").val() + "&curStepId=" + curStepId + "&optype=" + flag + "&Ieguid=" + GetGuid() + "'></iframe>");
        $("#modalwindow").window({ title: title, width: 860, height: 460, iconCls: 'fa fa-list' }).window('open');

    }

    function ICheck(remark, userid, flag, nextstepid) {

        $.post("@Url.Action("EditExternal")", { "Remark": remark, "TheSeal": "", "FormId": '@(Model.FormId)', "Flag": flag, "ContentId": $("#Id").val(), "UserList": userid, "NextStepId": nextstepid },
            function (data) {
                if (data.type == 1) {
                    if (nextstepid == '99') {
                        //结束流程
                        var childWindow = $("#ywForm")[0].contentWindow;
                        childWindow.updateState('@Model.Id', '@Model.FormId', 3);
                    }
                    else
                    {
                        if (nextstepid == '00') {
                            //结束流程
                            var childWindow = $("#ywForm")[0].contentWindow;
                            childWindow.updateState('@Model.Id', '@Model.FormId',4);
                        }
                        else
                        {
                            window.parent.frameReturnByMes(data.message);
                            window.parent.frameReturnByReload(true);
                            window.parent.frameReturnByClose();
                        }
                    }
                }
                else {
                    $.messageBox5s(Lang.Tip, data.message);
                }
            }, "json");
    }

    function ReturnByReload(flag) {
        window.parent.frameReturnByReload(flag);
    }

    function ReturnByClose() {
        window.parent.frameReturnByClose();
    }

    function ReturnByMes(mes) {
        window.parent.frameReturnByMes(mes);
    }
</script>
